import { LOGIN_TYPE, LOGOUT_TYPE } from '@/redux/constant';
let userInfo = localStorage.getItem('userInfo')
try {
    userInfo = JSON.parse(userInfo) || {}
} catch (err) {
    userInfo = {}
}
const reducer = function (state = userInfo, { type, payload }) {
    switch (type) {
        case LOGIN_TYPE:
            localStorage.setItem('userInfo', JSON.stringify(payload))
            return ({ ...payload });
        case LOGOUT_TYPE:
            localStorage.clear()
            return ({});

        default:
            return state

    }

}

export default reducer;